<template>
  <div class="popup" v-if="visible">
    <div class="popup-mask" @click="closePopup"></div>
    <div :class="[isContainer?'popup-content':'', positionClass]" style="z-index: 999;">
      <!-- 弹窗内容 -->
      <slot></slot>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    position: {
      type: String,
      default: 'center' // 默认居中位置
    },
    isContainer: {
      type: Boolean,
      default: true
    }
  },
  computed: {
    positionClass() {
      return `popup-${this.position}`;
    }
  },
  methods: {
    closePopup() {
      this.$emit('close');
    }
  }
}
</script>

<style scoped>
.popup {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
}

.popup-mask {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
}

.popup-content {
  margin: 0 15px;
  background-color: #fff;
  width: 100%;
  padding: 20px;
  border-radius: 10px;
}

.popup-bottom {
  position: absolute;
  bottom: 0px;
  border-radius: 30px 30px 0px 0px;
  padding: 0;
}
</style>